package com.liuanbang.saro.sarodemo.ui.activity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;

import com.liuanbang.saro.sarodemo.R;
import com.liuanbang.saro.sarodemo.base.BaseActivity;
import com.liuanbang.saro.sarodemo.util.ToastUtils;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘安邦 on 2017/3/13.
 * Email:liuanbang@aliyun.com
 * 描述:       2017/3/13
 * 修改:http://mp.weixin.qq.com/s/Shj2Uxdk3HOiTesvYmDAYw
 */

public class ToastDialogSanckbarActivity extends BaseActivity {
    @Bind(R.id.toast)
    Button toast;
    @Bind(R.id.dialog)
    Button dialog;
    @Bind(R.id.snackbar)
    Button snackbar;
    @Bind(R.id.toolBar)
    Toolbar toolBar;

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_toast_dialog_sanckbar);
        ButterKnife.bind(this);

        toolBar.setTitle("Toast/Dialog/Snackbar");
        toolBar.setBackgroundResource(R.color.color_main);
        //Toolbar 返回按钮
        toolBar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void setListener() {
        toast.setOnClickListener(this);
        dialog.setOnClickListener(this);
        snackbar.setOnClickListener(this);
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }

    @Override
    public Toolbar getToolbar() {
        return toolBar;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.toast:
                showToast();
                break;
            case R.id.dialog:
                showDialog();
                break;
            case R.id.snackbar:
                showSnackbar();
                break;
        }
    }

    private void showDialog() {
        //注意要使用这个包里面的android.support.v7.app.AlertDialog 才能保证不同版本风格相同,否则会出现不同版本显示不同
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("提示:").setIcon(R.drawable.ic_beiyong).setMessage("这只是一个提示而已....").setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        }).show();
    }

    private void showToast() {

        //解决多次点击 出现多次问题
        ToastUtils.showToast("Toast");
    }

    private void showSnackbar() {
        //使用前首先导入   compile 'com.android.support:design:23.4.0' 材料设计包
        Snackbar.make(snackbar, "这是Snackbar", Snackbar.LENGTH_SHORT).setAction("点击", new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        }).show();
    }
}
